package com.yy.controller.front;

import cn.hutool.core.util.RandomUtil;
import com.yy.entity.front.User;
import com.yy.service.front.UserService;
import com.yy.utils.R;
import com.yy.utils.RegexUtils;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.statement.select.KSQLWindow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * create by KongFuning on 2022/8/4
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    /*
    * 发送短信验证码
    * */
    @PostMapping("/code")
    public R sendCode(String phone){
        return userService.sendCode(phone);
    }

    /*
    * 登录
    * */
    @PostMapping("/login")
    public R login(HttpServletRequest request, @RequestBody Map loginMap){
        return userService.login(request,loginMap);
    }

    /*
    * 登出
    * */
    @PostMapping("/loginout")
    public R loginout(HttpServletRequest request){
        request.getSession().removeAttribute("user");
        return R.success("退出登录成功！");
    }
}
